//
//  CommodityManagementViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/6/30.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "CommodityManagementViewController.h"
#import "CommodityManagementTableViewCell.h"

static NSString * cellIndentifier = @"CommodityManagementTableViewCell";

@interface CommodityManagementViewController ()
<UITableViewDataSource,UITableViewDelegate>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIView *buttonView;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) IBOutlet UIButton *oneButton;
@property (strong, nonatomic) IBOutlet UIButton *twoButton;
@property (strong, nonatomic) IBOutlet UIButton *threeButton;
@property (strong, nonatomic) IBOutlet UIButton *fourButton;
@property (strong, nonatomic) IBOutlet UIView *sliderView;


@end

@implementation CommodityManagementViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initViewLayout];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.buttonView];
    
    [self.tableView registerNib:[UINib nibWithNibName:cellIndentifier bundle:nil] forCellReuseIdentifier:cellIndentifier];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

#pragma mark == 切换活动
- (IBAction)exchangeActivity:(UIButton *)sender {
    if (sender == _oneButton) {
        _oneButton.selected = YES;
        _twoButton.selected = NO;
        _threeButton.selected = NO;
        _fourButton.selected = NO;
        [UIView animateWithDuration:0.2 animations:^{
            _sliderView.frame = flexibleFrame(CGRectMake(0, 40, 80, 1), YES);
        }];
        [self.tableView reloadData];
    } else if (sender == _twoButton) {
        _oneButton.selected = NO;
        _twoButton.selected = YES;
        _threeButton.selected = NO;
        _fourButton.selected = NO;
        [UIView animateWithDuration:0.2 animations:^{
            _sliderView.frame = flexibleFrame(CGRectMake(80, 40, 80, 1), YES);
        }];
        [self.tableView reloadData];
    } else if (sender == _threeButton) {
        _oneButton.selected = NO;
        _twoButton.selected = NO;
        _threeButton.selected = YES;
        _fourButton.selected = NO;
        [UIView animateWithDuration:0.2 animations:^{
            _sliderView.frame = flexibleFrame(CGRectMake(160, 40, 80, 1), YES);
        }];
        [self.tableView reloadData];
    } else if (sender == _fourButton) {
        _oneButton.selected = NO;
        _twoButton.selected = NO;
        _threeButton.selected = NO;
        _fourButton.selected = YES;
        [UIView animateWithDuration:0.2 animations:^{
            _sliderView.frame = flexibleFrame(CGRectMake(240, 40, 80, 1), YES);
        }];
        [self.tableView reloadData];
    }

}

#pragma mark -- UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 154*VerticalRatio();
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CommodityManagementTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell == nil) {
        cell= [[CommodityManagementTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
    }
    
    return cell;
}




@end
